package com.lin.missyou.core;

import java.io.Serializable;

public class DeferReponse<T> implements Serializable {
    private static final long serialVersionUID = 1L;

    public static final Integer CODE_SUCCESS = 0;
    public static final Integer CODE_FAILED = -1;

    private int code;

    private String msg;

    private T data;

    /**
     * 空构造函数
     */
    public DeferReponse() {
        super();

    }
    /**
     * 全字段构造函数
     * @param code
     * @param msg
     * @param data
     */
    public DeferReponse(int code, String msg, T data) {
        super();
        this.code = code;
        this.msg = msg;
        this.data = data;
    }
    /**
     * 失败
     * @param message
     */
    public void fail(String message){
        this.setCode(CODE_FAILED);
        this.setMsg(message);
    }
    /**
     * 成功
     * @param message
     * @param data
     */
    public void success(String message,T data){
        this.setCode(CODE_SUCCESS);
        this.setMsg(message);
        this.setData(data);
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "ResponseMsg [code=" + code + ", msg=" + msg + ", data=" + data + "]";
    }

}
